package com.hy.hongying.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hy.hongying.bo.SelectVideoCommintBo;
import com.hy.hongying.bo.VideoCommintAddBo;
import com.hy.hongying.bo.VideoCommintMyBo;
import com.hy.hongying.dao.VideoCommitDao;
import com.hy.hongying.entity.VideoCommint;
import com.hy.hongying.service.intf.VideoCommintService;
import com.hy.hongying.third.BaiduCensorUtil;
import com.hy.hongying.util.BeanCopy;
import com.hy.hongying.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class VideoCommintServiceImpl implements VideoCommintService {
    @Autowired
    private VideoCommitDao vdao;
    /*
    添加视频和评论的  评论
     */
    @Override
    public R insertVideoCommint(String token, VideoCommintAddBo bo) {
        if (token==null||token.length()==0){
            return R.fail("亲你还没有登录的哦");
        }
        if (bo.getInfo()!=null&&bo.getInfo().length()>0&&BaiduCensorUtil.textCensor(bo.getInfo())) {
            VideoCommint trance = BeanCopy.getTrance(VideoCommint.class, bo);
            trance.setFlag(1);
            trance.setCtime(new Date());
            int insert = vdao.insert(trance);
            if (insert>0){
                return R.ok();
            }
        }
        return R.fail("文明发言，社会你我他她.......");

    }
    /*
    产看自己的所有的评论
     */
    @Override
    public R selectMyVideoCommint(String token, Integer uid) {
        if (token==null||token.length()==0){
            return R.fail("亲你还没有登录的哦");
        }
        if (uid==0){
            return R.fail("亲数据异常，请退出登录尝试");
        }
        List<VideoCommintMyBo> videoCommintMyBos = vdao.selectMyVideoCommint(uid);
        if (videoCommintMyBos.size()>0){
            return R.ok(videoCommintMyBos);
        }
        return R.ok("你还没有发布动态的哦亲！！！");
    }
    /*
    删除自己的发的评论
     */
    @Override
    public R delMyVideoCommint(String token, Integer cid) {
        if (token==null||token.length()==0){
            return R.fail("亲系统异常！请稍后尝试");
        }
        if (cid>0){
            int i = vdao.delMyVideoCommint(cid);
            if (i>0){
                return R.ok("删除成功");
            }
        }

        return R.fail("数据异常");
    }
    /*

     */
    @Override
    public R selectVideoCommint(Integer vid) {
        if (vid==null || vid==0){
            return R.fail("数据异常");
        }
        List<SelectVideoCommintBo> selectVideoCommintBos = vdao.selectVideoCommintBo(vid);
        if (selectVideoCommintBos==null||selectVideoCommintBos.size()==0){
            return R.ok("暂时没有评论");
        }
        for (SelectVideoCommintBo bo:
                selectVideoCommintBos ) {
            bo.setNum(vdao.getVideoCommintBoNums(bo.getCid()));
        }
        return R.ok(selectVideoCommintBos);

    }
    public R selectVideoCommints(Integer cid){
        if (cid==null || cid==0){
            return R.fail("数据异常");
        }
        List<SelectVideoCommintBo> selectVideoCommintBos = vdao.selecCommintPreBo(cid);
        if (selectVideoCommintBos==null||selectVideoCommintBos.size()==0){
            return R.ok("暂时没有评论");
        }
        for (SelectVideoCommintBo bo:
                selectVideoCommintBos ) {
            bo.setNum(vdao.getCommintPreBoNums(bo.getCid()));
        }
        return R.ok(selectVideoCommintBos);
    }


}
